from wordcloud import WordCloud
import matplotlib.pyplot as plt
import jieba
text= open('./1.txt',encoding="utf-8").read()
font = r'C:\Windows\Fonts\simfang.ttf'

wordlist_after_jieba = jieba.cut_for_search(text)
wl_space_split = " ".join(wordlist_after_jieba)
wc = WordCloud(collocations=False, font_path=font, width=2400, height=2400, margin=2).generate(wl_space_split)

plt.imshow(wc)
plt.axis("off")
plt.show()

# wc.to_file('show_Chinese.png')  # 把词云保存下来
#
# text_from_file_with_apath = open('./test.txt',encoding="utf-8").read()
# wordlist_after_jieba = jieba.cut(text_from_file_with_apath, cut_all=True)
# wl_space_split = " ".join(wordlist_after_jieba)
# my_wordcloud = WordCloud().generate(wl_space_split)
# plt.imshow(my_wordcloud)
# plt.axis("off")
# plt.show()